<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>父子组件传值</title>
  <script src="../asset/js/vue.js"></script>
</head>

<body>
  <div id="root">
    <counter ref='one' :count='0' @inc='handleIncrease'></counter>
    <counter ref='two' :count='1' @inc='handleIncrease'></counter>
    <div>{{newTotal}}</div>
  </div>
  <script>
    let counter = {
      props: ['count'],
      data() {
        return {
          number: this.count
        }
      },
      template: `<button @click='handleClick'>{{number}}</button>`,
      methods: {
        handleClick() {
          this.number++;
          this.$emit('inc', 1)
        }
      }
    }
    let vm = new Vue({
      el: '#root',
      data: {
        total: 1
      },
      components: {
        counter,
      },
      computed: {
        newTotal() {
          return this.total
        }
      },
      methods: {
        handleIncrease(step) {
          this.total += step
        }
      }
    })
  </script>
</body>

</html>